# from app import db_analytics
from app.databases import db_main
from app.models.analytics.user_analytics_model import UserAnalytics
from app.models.user_model import User
# from app import db_main
# from app.models.user_model import User
# from app.models.analytics.user_analytics_model import UserAnalytics

class ProductService:
    @staticmethod
    def create_user(data):
        # new_user = User(
        #     username=data['username'],
        #     email=data['email']
        # )
        # db_main.session.add(new_user)
        # db_main.session.commit()

        # 同时在分析数据库中创建记录
        new_analytics = UserAnalytics(
            # user_id=new_user.id,
            login_count=0
        )
        db_main.session.add(new_analytics)
        db_main.session.commit()

        return new_analytics

    @staticmethod
    def get_all_products():
        """获取所有用户"""
        try:
            users = UserAnalytics.query.all()  # 假设你的User模型是SQLAlchemy模型
            return users
        except Exception as e:
            # 可以记录日志
            print(f"获取用户列表失败: {str(e)}")
            raise  # 重新抛出异常，由路由处理
